﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace Revis.VClinicNet.UI.Internal.Mvc.Extensions
{
    public static class ViewDataDictionaryExtension
    {
        public static string InstanceItemKey<T>(
            this ViewDataDictionary session) where T : class
        {
            return typeof(T).FullName;
        }

        public static void AddInstance<T>(
            this ViewDataDictionary s,
            T item) where T : class
        {
            s.Add(s.InstanceItemKey<T>(), item);
        }

        public static T GetInstance<T>(
            this ViewDataDictionary s) where T : class
        {
            return s[s.InstanceItemKey<T>()] as T;
        }

        public static void RemoveInstance<T>(
            this ViewDataDictionary s) where T : class
        {
            s.Remove(s.InstanceItemKey<T>());
        }
    }
}
